import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      body: NestedScrollView(
        body: ListView.builder(
          padding: EdgeInsets.only(left: 12, right: 12),
          itemCount: 100,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              margin: EdgeInsets.only(bottom: 10),
              child: Row(
                children: [
                  //左侧图片
                  Image.asset(
                    'asset/images/s02.png',
                    width: 100,
                    height: 60,
                    fit: BoxFit.cover,
                  ),
                  SizedBox(width: 12),
                  //右侧内容
                  Expanded(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '这里是标题 $index',
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                        SizedBox(height: 6),
                        Text(
                          '这里是内容这里是内容这里是内容这里是内容这里是内容 ',
                          style: TextStyle(fontSize: 14, color: Colors.grey),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            );
          },
        ),
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return [
            // SliverToBoxAdapter(child: Image.asset('asset/images/s03.png')),
            SliverAppBar(
              expandedHeight: 240,
              floating: true,
              snap: true,
              pinned: true,
              flexibleSpace: FlexibleSpaceBar(
                title: Text('详情'),
                background: Image.asset(
                  'asset/images/s03.png',
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ];
        },
      ),
    );
  }
}
